package com.example.demo.web;

import com.example.demo.ov.req.BucketRemoveReq;
import com.example.demo.ov.req.FileDeleteReq;
import com.example.demo.ov.req.FileDownloadReq;
import com.example.demo.ov.req.FileUploadReq;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * MinIO文件管理
 *
 * @author yz
 */
@RestController
@RequestMapping("/demo")
@Slf4j
public class FileSystemController {

    @Resource
    private FileSystemService fileSystemService;

    @PostMapping(value = "/fileUploadByFilePath")
    public void fileUploadByFilePath(@RequestBody FileUploadReq fileUploadReq) {
        fileSystemService.fileUploadByFilePath(fileUploadReq.getObjectName(), fileUploadReq.getFilePath());
    }

    @PostMapping(value = "/fileUploadByImageData")
    public void fileUploadByImageData(@RequestBody FileUploadReq fileUploadReq) {
        fileSystemService.fileUploadByImageData(fileUploadReq.getObjectName(), fileUploadReq.getImageData());
    }

    @GetMapping(value = "/fileDownload")
    public void fileDownload(@RequestBody FileDownloadReq fileDownloadReq) {
        fileSystemService.fileDownload(fileDownloadReq.getObjectName(), fileDownloadReq.getTargetFilePath());
    }

    @PostMapping("/bucketRemove")
    public void bucketRemove(@RequestBody BucketRemoveReq bucketRemoveReq) {
        fileSystemService.bucketRemove(bucketRemoveReq.getBucketName());
    }

    @PostMapping("/fileDelete")
    public void fileDelete(@RequestBody FileDeleteReq fileDeleteReq) {
        fileSystemService.fileDelete(fileDeleteReq.getObjectName());
    }

    @GetMapping(value = "/getPicture")
    public ResponseEntity<byte[]> getPicture(String pic) {
        return fileSystemService.getPicture(pic);
    }
}
